﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Billing.WindowsBase;
using Billing.DataObjects;

namespace Billing.Windows.Shell.SystemObjects
{
    public partial class FormGroups : BaseList
    {
        ShellDataContext mShellDataContext = new ShellDataContext();

        #region Constructors
        public FormGroups()
        {
            InitializeComponent();
        }

        public FormGroups(bool Register)
            : base(Register)
        {
            InitializeComponent();
        }

        #endregion

        #region Overrides

        protected override void onDataLoad()
        {
            base.onDataLoad();
            bsElement.DataSource = mShellDataContext.FormGroups;
            this.ElementRowTemplate = ultraGridRowEditTemplate1;
        }
        protected override void onDelete()
        {
            base.onDelete();
            bsElement.RemoveCurrent();
            this.onDataLoad();
        }
        protected override void onAfterInitialize()
        {
            base.onAfterInitialize();
            this.ElementNameID = "frmgID";
        }
        protected override void onSave()
        {
            base.onSave();
            mShellDataContext.SubmitChanges();
        }
        protected override void onClose()
        {
            if (AllowSave && (mShellDataContext.GetChangeSet().Deletes.Count > 0
                || mShellDataContext.GetChangeSet().Updates.Count > 0
                || mShellDataContext.GetChangeSet().Inserts.Count > 0))
            {
                if (MessageBox.Show("შევინახო შეცვლილი მონაცემები?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    mShellDataContext.SubmitChanges();
            }
            base.onClose();
        }
        #endregion

        private void btnTemplateOk_Click(object sender, EventArgs e)
        {
            // This code was automatically generated by the RowEditTemplate Wizard
            // 
            // Close the template and save any pending changes.
            if (comboBox1.SelectedIndex == 0)
            {
                grd.Selected.Rows[0].Cells["StatusID"].Value = 1;
            }
            else
            {
                grd.Selected.Rows[0].Cells["StatusID"].Value = 0;
            }
            this.ultraGridRowEditTemplate1.Close(true);
        }

        private void btnTemplateCancel_Click(object sender, EventArgs e)
        {
            // This code was automatically generated by the RowEditTemplate Wizard
            // 
            // Close the template and discard any pending changes.
            this.ultraGridRowEditTemplate1.Close(false);
        }
        protected override void onElementInitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            base.onElementInitializeLayout(sender, e);
            grd.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect;
            if (e.Layout.Bands[0].Columns.Count > 0)
            {
                e.Layout.Bands[0].Columns["GUID"].Hidden = true;
                e.Layout.Bands[0].Columns["ModifierID"].Hidden = true;
                e.Layout.Bands[0].Columns["ModifiedDate"].Hidden = true;
                e.Layout.Bands[0].Columns["Icon"].Hidden = true;
                e.Layout.Bands[0].Columns["StatusID"].Hidden = true;
                e.Layout.Bands[0].Columns["IconName"].Hidden = true;

                e.Layout.Bands[0].Columns["ID"].Header.Caption = "ინდექსი";
                e.Layout.Bands[0].Columns["Key"].Header.Caption = "უნიკალური ველი";
                e.Layout.Bands[0].Columns["Name"].Header.Caption = "სახელი";
                e.Layout.Bands[0].Columns["CreatorID"].Header.Caption = "შემქმნელი";
                e.Layout.Bands[0].Columns["CreatedDate"].Header.Caption = "შექმნის თარიღი";
                e.Layout.Bands[0].Columns["SID"].Header.Caption = "სორტირების ინდექსი";
            }
        }

        private void ultraGridRowEditTemplate1_Enter(object sender, EventArgs e)
        {
            if (Convert.ToInt32(grd.Selected.Rows[0].Cells["StatusID"].Value) == 0)
            {
                comboBox1.SelectedIndex = 1;
            }
            else
            {
                comboBox1.SelectedIndex = 0;
            }
        }

    }
}
